import 'package:flutter/material.dart';
import 'package:provide/provide.dart';
import '../../provide/goods_detail_provide.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';

class DetailsTopArea extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Provide<GoodsDetailProvide>(
      builder: (context, child, val) {
        var goodsInfo = Provide.value<GoodsDetailProvide>(context)
            .goodsDetail
            .data
            .goodInfo;
        if (goodsInfo != null) {
          return Container(
            color: Colors.white,
            padding: EdgeInsets.all(2),
            child: Column(
              children: <Widget>[
                _goodsImage(goodsInfo.image1),
                _goodsName(goodsInfo.goodsName),
                _goodsNum(goodsInfo.goodsSerialNumber),
                _goodsPrice(goodsInfo.presentPrice, goodsInfo.oriPrice)
              ],
            ),
          );
        } else {
          return Text('暂无数据');
        }
      },
    );
  }

  /**
   * 商品图片
   */
  Widget _goodsImage(String url) {
    return Image.network(
      url,
      width: ScreenUtil().setWidth(740),
    );
  }

  /**
   * 商品名称
   */
  Widget _goodsName(String name) {
    return Container(
      width: ScreenUtil().setWidth(730),
      padding: EdgeInsets.only(top: 15),
      margin: EdgeInsets.only(left: 15),
      child: Text(
        name,
        maxLines: 1,
        style: TextStyle(fontSize: ScreenUtil().setSp(30)),
      ),
    );
  }

  /**
   * 商品编号
   */
  Widget _goodsNum(String num) {
    return Container(
      width: ScreenUtil().setWidth(730),
      padding: EdgeInsets.only(left: 15),
      margin: EdgeInsets.only(top: 8.0),
      child: Text('编号：${num}', style: TextStyle(color: Colors.black26)),
    );
  }

  /**
   * 商品价格
   */
  Widget _goodsPrice(double price1, double price2) {
    return Container(
      width: ScreenUtil().setWidth(730),
      padding: EdgeInsets.only(left: 15),
      margin: EdgeInsets.only(top: 8),
      child: Row(
        children: <Widget>[
          Text(
            '￥${price1}',
            style:
                TextStyle(color: Colors.pink, fontSize: ScreenUtil().setSp(40)),
          ),
          Text(
            '市场价：￥${price2}',
            style: TextStyle(
                color: Colors.black26, decoration: TextDecoration.lineThrough),
          ),
        ],
      ),
    );
  }
}
